﻿Public Class Frm_LoTransportStation
    Implements IDServer.IDServer.IDServer
    Private WithEvents MainForm As Frm_MainForm
    Private mDataset As DataSet
    Private RST As DataSet
    Private MDatatable As DataTable
    Private Mtable As DataTable


    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property

#Region "interface Define"
    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd
        Try
            If AddEnable = False Then
                MessageBox.Show("對不起，您沒有新增權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Me.Tabcontrol1.SelectedIndex = 1
            Dim B As Boolean = True
            ControlEnable(B)
            ClearControl()
            ActionButtonENABLE()
        Catch ex As Exception

        End Try
    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel
        Try
            Dim B As Boolean = False
            ControlEnable(B)
            MainForm.ToolStripCancel.Enabled = False
            MainForm.ToolStripSave.Enabled = False
            MainForm.ToolStripAdd.Enabled = True
        Catch ex As Exception

        End Try
    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete
        Try
            If DeleteEnable = False Then
                MessageBox.Show("對不起，您沒有刪除權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If MessageBox.Show("您確定要刪除? ", Msg.CompanyName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
                If Me.DgvMaster.Rows.Count > 0 Then
                    Dim fStationID As String = Me.DgvMaster.CurrentRow.Cells("fStationID").Value
                    Dim Rows() As DataRow = RST.Tables(0).Select("fStationID='" & fStationID & "'")
                    For Each row As DataRow In Rows
                        RST.Tables(0).Rows.Remove(row)
                    Next
                    RST.AcceptChanges()
                    Dim Sqlstr As String = "delete from Lo_TranStation where fStationID='" & fStationID & "'"
                    ReturnObject(Sqlstr)

                End If
            End If
        Catch ex As Exception

        End Try
    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit
        If EditEnable = False Then
            MessageBox.Show("對不起，您沒有修改權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If

    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave
        Try
            If ConditionToSave() = False Then Exit Function


            Dim fTranMethod As String = Me.CmbTranMethod.SelectedValue
            Dim fStationID As String = Me.TxtStationID.Text
            Dim fStationName As String = Me.TxtStationName.Text
            Dim fCountry As String = Me.CmbCountry.SelectedValue
            Dim fCity As String = Me.CmbCity.SelectedValue
            Dim fArea As String = Me.CmbArea.SelectedValue
            Dim fRemark As String = Me.TxtRemark.Text
            Dim SQL As String = ""


            If IsorExit() = True Then
                SQL = "insert into Lo_TranStation(fTranMethod, fStationID, fStationName, fCountry, fCity, fArea, fRemark) values('" & fTranMethod & "','" & fStationID & "','" & fStationName & "','" & fCountry & "','" & fCity & "','" & fArea & "','" & fRemark & "') "
            Else
                SQL = "Update Lo_TranStation set fTranMethod='" & fTranMethod & "', fStationName='" & fStationName & "',fCountry='" & fCountry & "',fCity='" & fCity & "',fArea='" & fArea & "',fRemark='" & fRemark & "' where fStationID='" & fStationID & "'"
            End If

            ReturnDataset(SQL)
            FILLdgv()
            MessageBox.Show("設置成功", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)

            MainForm.ToolStripAdd.Enabled = True
            MainForm.ToolStripSave.Enabled = False
            MainForm.ToolStripCancel.Enabled = False

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function

    Private Sub ComboBox7_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbCountryQ.SelectedIndexChanged

    End Sub


#End Region

#Region "Sub and Function"

    Private Function ConditonToQuery() As String
        Try
            Dim SQL As String = ""
            Dim fTranMethod As String = Me.CmbTranMethodQ.SelectedValue.ToString.Trim
            Dim fStationID As String = Me.TxtStationIDQ.Text.ToString.Trim
            Dim fStationName As String = Me.TxtStationNameQ.ToString.Trim
            Dim fCountry As String = Me.CmbCountryQ.SelectedValue.ToString.Trim
            Dim fCity As String = Me.CmbCityQ.SelectedValue.ToString.Trim
            Dim fArea As String = Me.CmbAreaQ.SelectedValue.ToString.Trim

            If Me.CmbTranMethod.Text.Length > 0 Then
                SQL = SQL & " and fTranMethod='" & fTranMethod & "'"
            End If
            If Me.TxtStationID.Text.Length > 0 Then
                SQL = SQL & " and fStationID='" & fStationID & "'"
            End If
            If Me.TxtStationName.Text.Length > 0 Then
                SQL = SQL & " and fStationName='" & fStationName & "'"
            End If
            If Me.CmbCountry.Text.Length > 0 Then
                SQL = SQL & " and fCountry='" & fCountry & "'"
            End If
            If Me.CmbCity.Text.Length > 0 Then
                SQL = SQL & " and fCity='" & fCity & "'"
            End If
            If Me.CmbArea.Text.Length > 0 Then
                SQL = SQL & " and fArea='" & fArea & "'"
            End If
            Return SQL
        Catch ex As Exception

        End Try
    End Function

    Private Sub BtnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnQuery.Click
        Try
            Dim sql As String = ""
            RST = New DataSet
            sql = "select * from Lo_TranStation  where 1=1 " & ConditonToQuery()
            RST = ReturnDataset(sql)
            Me.DgvMaster.DataSource = RST.Tables(0)
        Catch ex As Exception

        End Try

    End Sub

    Private Sub FILLdgv()
        Try
            MDatatable.Rows.Clear()
            Dim row As DataRow = MDatatable.NewRow
            row("fTranMethod") = Me.CmbTranMethod.Text
            row("fStationID") = Me.TxtStationID.Text
            row("fStationName") = Me.TxtStationName.Text
            row("fCountry") = Me.CmbCountry.Text
            row("fCity") = Me.CmbCity.Text
            row("fArea") = Me.CmbArea.Text
            row("fRemark") = Me.TxtRemark.Text
            MDatatable.Rows.Add(row)
            Me.DgvMaster.DataSource = MDatatable
            Me.DgvDetail.DataSource = MDatatable


        Catch ex As Exception

        End Try
    End Sub

    Private Sub ActionButtonENABLE()
        With MainForm
            .ToolStripAdd.Enabled = False
            .ToolStripCancel.Enabled = True
            .ToolStripCheck.Enabled = False
            .ToolStripEdit.Enabled = False
            .ToolStripSave.Enabled = True
        End With
    End Sub

    Private Sub Frm_LoTransportStation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim B As Boolean = False
            ControlEnable(B)
            LoadCombControl()
            BindDgvDetail()
            BindDgvMaster()
            BindDgvDistance()
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Private Sub ControlEnable(ByVal B As Boolean)
        Try
            Me.CmbTranMethod.Enabled = B
            Me.TxtStationID.Enabled = B
            Me.TxtStationName.Enabled = B
            Me.CmbCountry.Enabled = B
            Me.CmbCity.Enabled = B
            Me.CmbArea.Enabled = B
            Me.TxtRemark.Enabled = B
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub ClearControl()
        Try
            Me.CmbTranMethod.Text = ""
            Me.TxtStationID.Text = ""
            Me.TxtStationName.Text = ""
            Me.CmbCountry.Text = ""
            Me.CmbCity.Text = ""
            Me.CmbArea.Text = ""
            Me.TxtRemark.Text = ""
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub LoadCombControl()

        'Dim nTable As DataTable

        Try
            Dim SQL As String = ""
            Dim RST As DataSet
            SQL = "SELECT * FROM dbo.LO_AreaSetup Where fAreaOrg='0';"
            SQL = SQL & "select * from lo_areasetup where  Fareaorg in (SELECT fAreaID FROM dbo.LO_AreaSetup Where fAreaOrg='0');"
            SQL = SQL & "select * from LO_AreaSetup where fAreaOrg in (select fAreaID from LO_AreaSetup where fAreaOrg in (select fAreaID from dbo.LO_AreaSetup where fAreaOrg='0'));"
            SQL = SQL & "select * from dbo.BSC_OtherDefineA a, dbo.BSC_OtherDefineb b where a.ID=b.itemNo and b.itemNo='75';"
            SQL = SQL & "select * from dbo.Lo_TranStation;"
            SQL = SQL & "select * from dbo.Lo_TranStation"
            RST = ReturnDataset(SQL)
            With Me.CmbCountry
                .DataSource = RST.Tables(0)
                .ValueMember = "fAreaID"
                .DisplayMember = "fAreaName"
            End With
            With Me.CmbCountryQ
                .DataSource = RST.Tables(0)
                .ValueMember = "fAreaID"
                .DisplayMember = "fAreaName"
            End With
            With Me.CmbCity
                .ValueMember = "fAreaID"
                .DisplayMember = "fAreaName"
                .DataSource = RST.Tables(1)
            End With

            With Me.CmbCityQ
                .ValueMember = "fAreaID"
                .DisplayMember = "fAreaName"
                .DataSource = RST.Tables(1)
            End With

            With Me.CmbArea
                .ValueMember = "fAreaID"
                .DisplayMember = "fAreaName"
                .DataSource = RST.Tables(2)
            End With

            With Me.CmbAreaQ
                .ValueMember = "fAreaID"
                .DisplayMember = "fAreaName"
                .DataSource = RST.Tables(2)
            End With

            With Me.CmbTranMethod
                .ValueMember = "ListCode"
                .DisplayMember = "ListA"
                .DataSource = RST.Tables(3)
            End With

            With Me.CmbTranMethodQ
                .ValueMember = "ListCode"
                .DisplayMember = "ListA"
                .DataSource = RST.Tables(3)
            End With

            With Me.CmbTransportMethod
                .ValueMember = "ListCode"
                .DisplayMember = "ListA"
                .DataSource = RST.Tables(3)
            End With

            With Me.CmbStart
                .DisplayMember = "fStationName"
                .ValueMember = "fStationID"
                .DataSource = RST.Tables(4)
                .DropDownStyle = ComboBoxStyle.DropDownList
            End With

            With Me.ComboBox1
                .DisplayMember = "fStationName"
                .ValueMember = "fStationID"
                .DataSource = RST.Tables(5)
                .SelectedIndex = -1
            End With
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Function ConditionToSave() As Boolean
        Try
            Dim B As Boolean
            B = True
            If Me.CmbTranMethod.Text = "" Then
                B = False
                Exit Function
            End If
            If Me.TxtStationID.Text = "" Then
                B = False
                Exit Function
            End If
            If Me.TxtStationName.Text = "" Then
                B = False
                Exit Function
            End If
            If Me.CmbCountry.Text = "" Then
                B = False
                Exit Function
            End If
            If Me.CmbCity.Text = "" Then
                B = False
                Exit Function
            End If
            If Me.CmbArea.Text = "" Then
                B = False
                Exit Function
            End If
            Return B
        Catch ex As Exception

        End Try

    End Function

    Private Function IsorExit() As Boolean
        Try
            Dim B As Boolean = False
            Dim fStationID As String = Me.TxtStationID.Text
            Dim SQLstr As String = ""
            Dim RST As DataSet
            SQLstr = "select * from Lo_TranStation where fStationID='" & fStationID & "' "
            RST = New DataSet
            RST = ReturnDataset(SQLstr)

            If RST.Tables(0).Rows.Count > 0 Then
                B = False
                Exit Function
            Else
                B = True
            End If
            Return B
        Catch ex As Exception

        End Try

    End Function

#End Region

#Region "Bind Datagridview "

    Private Sub BindDgvMaster()
        Try
            MDatatable = New DataTable
            With MDatatable.Columns
                .Add("fTranMethod")
                .Add("fStationID")
                .Add("fStationName")
                .Add("fCountry")
                .Add("fCity")
                .Add("fArea")
                .Add("fRemark")
            End With
            'mDataset = New DataSet
            'mDataset.Tables.Add(Mtable)
            Me.DgvMaster.DataSource = MDatatable

            With Me.DgvMaster
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindCaptionStr(0).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                Next
            End With
        Catch ex As Exception

        End Try
    End Sub

    Private Sub BindDgvDetail()
        Try
            MDatatable = New DataTable
            With MDatatable.Columns
                .Add("fTranMethod")
                .Add("fStationID")
                .Add("fStationName")
                .Add("fCountry")
                .Add("fCity")
                .Add("fArea")
                .Add("fRemark")
            End With
            'mDataset = New DataSet
            'mDataset.Tables.Add(Mtable)
            Me.DgvDetail.DataSource = MDatatable
            With Me.DgvDetail
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindCaptionStr(1).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr 
                Next
                .Columns(8).DefaultCellStyle.BackColor = Color.DarkBlue
            End With
        Catch ex As Exception

        End Try
    End Sub

    Private Sub BindDgvDistance()
        Try
            Mtable = New DataTable
            With Mtable.Columns
                .Add("fID")
                .Add("fTranMethod")
                .Add("fStart")
                .Add("fEnd")
                .Add("fAccount")
            End With
            'mDataset = New DataSet
            'mDataset.Tables.Add(Mtable)
            Me.DgvDistance.DataSource = Mtable
            With Me.DgvDistance
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindCaptionStr(2).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                Next
            End With
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Function BindCaptionStr(ByVal index As Integer) As Hashtable
        Try
            Dim mTable As New Hashtable
            With mTable
                Select Case index
                    Case 0
                        .Add("fTranMethod", "運輸方式")
                        .Add("fStationID", "站點編號")
                        .Add("fStationName", "站點")
                        .Add("fCountry", "國家")
                        .Add("fCity", "城市")
                        .Add("fArea", "地區")
                        .Add("fRemark", "備註")
                    Case 1
                        .Add("fTranMethod", "運輸方式")
                        .Add("fStationID", "站點編號")
                        .Add("fStationName", "站點")
                        .Add("fCountry", "國家")
                        .Add("fCity", "城市")
                        .Add("fArea", "地區")
                        .Add("fRemark", "備註")
                    Case 2
                        .Add("fID", "編號")
                        .Add("fTranMethod", "運輸方式")
                        .Add("fStart", "起始站")
                        .Add("fEnd", "終點站")
                        .Add("fAccount", "公里數")
                End Select

                Return mTable
            End With
        Catch ex As Exception
        End Try
    End Function
#End Region

    Private Function ConditonForSave() As Boolean

        Try
            Dim B As Boolean = True
            If Me.TxtID.Text = "" Then
                MessageBox.Show("編號為空", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                B = False
                Exit Function
            End If
            If Me.CmbTransportMethod.Text = "" Then
                MessageBox.Show("運輸方式為空", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                B = False
                Exit Function
            End If
            If Me.CmbStart.Text = "" Then
                MessageBox.Show("起始站為空", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                B = False
                Exit Function
            End If
            If Me.ComboBox1.Text = "" Then
                MessageBox.Show("終點為空", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                B = False
                Exit Function
            End If
            If Me.TxtAccount.Text = "" Then
                MessageBox.Show("公里數為空", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                B = False
                Exit Function
            End If
            Return B
        Catch ex As Exception

        End Try
    End Function

    Private Function ConditionForSave() As Boolean
        Try
            Dim B As Boolean = True
            Dim strSQL As String = ""
            Dim fID As String = Me.TxtID.Text
            Dim RST As New DataSet

            strSQL = "select * from Lo_DistanceSetup where fID='" & fID & "'"
            RST = ReturnDataset(strSQL)

            If RST.Tables(0).Rows.Count > 0 Then
                B = False
            Else
                B = True
            End If
            Return B

        Catch ex As Exception

        End Try

    End Function

    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try

            If ConditonForSave() = False Then Exit Sub

            Dim fID As String = Me.TxtID.Text.ToString.Trim
            Dim fTranMethod As String = Me.CmbTransportMethod.SelectedValue
            Dim fStart As String = Me.CmbStart.SelectedValue
            Dim fEnd As String = Me.ComboBox1.SelectedValue
            Dim fAccount As String = Me.TxtAccount.Text.ToString.Trim
            Dim Strsql As String = ""
            Dim RST As New DataSet

            If ConditionForSave() = True Then
                Strsql = "INSERT INTO dbo.Lo_DistanceSetup(fID, fTranMethod, fStart, fEnd, fAccount) " & vbCrLf
                Strsql = Strsql & "values ('" & fID & "', '" & fTranMethod & "', '" & fStart & "', '" & fEnd & "', '" & fAccount & "') "
            Else
                Strsql = "update Lo_DistanceSetup set" & vbCrLf
                Strsql = Strsql & " fTranMethod='" & fTranMethod & "'," & vbCrLf
                Strsql = Strsql & " fStart='" & fStart & "', " & vbCrLf
                Strsql = Strsql & " fEnd='" & fEnd & "'," & vbCrLf
                Strsql = Strsql & " fAccount='" & fAccount & "' where fID='" & fID & "' " & vbCrLf
            End If

            ReturnObject(Strsql)
            'Mtable.Rows.Clear()
            Dim newrow As DataRow = Mtable.NewRow
            newrow("fID") = fID
            newrow("fTranMethod") = fTranMethod
            newrow("fStart") = Me.CmbStart.Text
            newrow("fEnd") = Me.ComboBox1.Text
            newrow("fAccount") = fAccount
            Mtable.Rows.Add(newrow)
            Me.DgvDistance.DataSource = Mtable
            MessageBox.Show("保存成功", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub 刪除ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 刪除ToolStripMenuItem.Click
        Try
            If Me.DgvDistance.RowCount > 0 Then
                Dim fID As String = Me.DgvDistance.CurrentRow.Cells("fID").Value
                Dim fTranMethod As String = Me.DgvDistance.CurrentRow.Cells("fTranMethod").Value
                Dim fStart As String = Me.DgvDistance.CurrentRow.Cells("fStart").Value
                Dim fEnd As String = Me.DgvDistance.CurrentRow.Cells("fEnd").Value
                Dim fAccount As String = Me.DgvDistance.CurrentRow.Cells("fAccount").Value

                'Me.TxtID.Text = fID
                'Me.CmbTransportMethod.SelectedIndex = fTranMethod
                'Me.CmbStart.SelectedIndex = fStart
                'Me.ComboBox1.SelectedIndex = fEnd
                'Me.TxtAccount.Text = fAccount

                Dim strsql = "delete  Lo_DistanceSetup where fID='" & fID & "'"
                ReturnObject(strsql)

                Me.DgvDistance.Rows.Remove(Me.DgvDistance.CurrentRow)


            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub DgvDistance_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvDistance.CellClick
        Try
            If Me.DgvDistance.RowCount > 0 Then
                Dim fID As String = Me.DgvDistance.CurrentRow.Cells("fID").Value
                Dim fTranMethod As String = Me.DgvDistance.CurrentRow.Cells("fTranMethod").Value
                Dim fStart As String = Me.DgvDistance.CurrentRow.Cells("fStart").Value
                Dim fEnd As String = Me.DgvDistance.CurrentRow.Cells("fEnd").Value
                Dim fAccount As String = Me.DgvDistance.CurrentRow.Cells("fAccount").Value

                Me.TxtID.Text = fID
                Me.CmbTransportMethod.SelectedIndex = fTranMethod
                Me.CmbStart.SelectedIndex = fStart
                Me.ComboBox1.SelectedIndex = fEnd
                Me.TxtAccount.Text = fAccount
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Function QueryConditions()
        Try
            Dim SQL As String
            If Me.TxtID.Text.Length > 0 Then
                SQL = " and c.fID='" & Me.TxtID.Text.ToString.Trim & "'"
            End If
            If Me.CmbTransportMethod.Text.Length > 0 Then
                SQL = SQL & " and c.fTranMethod='" & Me.CmbTransportMethod.SelectedValue.ToString.Trim & "'"
            End If
            If Me.CmbStart.Text.Length > 0 Then
                SQL = SQL & " and  c.fStart='" & Me.CmbStart.Text.ToString.Trim & "'"
            End If
            If Me.ComboBox1.Text.Length > 0 Then
                SQL = SQL & " and  d.fEnd='" & Me.ComboBox1.Text.ToString.Trim & "'"
            End If
            Return SQL

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub BtndistanceQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtndistanceQuery.Click
        Try

            Dim SQL As String = ""
            Dim RST As New DataSet
            SQL = "select  c.fID,c.fTranMethod,c.fstart,d.fEND,c.fAccount from (select a.fID,a.fTranMethod,b.fStationName  AS fStart ,a.fAccount from Lo_DistanceSetup a,Lo_TranStation b where a.fStart=b.fStationID)c,(select a.fID,a.fTranMethod,b.fStationName  AS fEnd from Lo_DistanceSetup a,Lo_TranStation b where a.fEnd=b.fStationID) d where c.fid =d.fid and 1=1 " & QueryConditions()
            RST = ReturnDataset(SQL)
            Me.DgvDistance.DataSource = RST.Tables(0)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub DgvMaster_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvMaster.CellClick
        Try
            If Me.DgvMaster.Rows.Count > 0 Then
                MainForm.ToolStripDelete.Enabled = True
            Else
                MainForm.ToolStripDelete.Enabled = True
            End If
        Catch ex As Exception

        End Try
    End Sub


    Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter

    End Sub
End Class
